<template>
  <div>
    <el-table
      :data="manageList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="用户编号"> </el-table-column>
      <el-table-column prop="username" label="用户名称"> </el-table-column>
      <el-table-column prop="rolename" label="所属角色"> </el-table-column>

      <el-table-column prop="status" label="状态">
        <template slot-scope="scoped">
          <div>
            <el-button v-if="scoped.row.status == 1" type="primary"
              >启用</el-button
            >
            <el-button v-else type="info">禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scoped">
          <div>
            <el-button @click="edit(scoped.row.uid)">编辑</el-button>
            <el-button @click="del(scoped.row.uid)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="manageCount"
      :page-size="manageSize"
      @current-change="changePage"
    >
    </el-pagination>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { userDelete } from "../../../request/api";
import { successAlert, warningAlert } from "../../../utils/alert";
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      asyncManageList: "manage/asyncChangeList",
      asyncManageCount: "manage/asyncChangeCount",
      asyncManagePage:"manage/asyncChangePage"
    }),
    del(uid) {
      {
        this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            userDelete({ uid: uid }).then((res) => {
              if (res.data.code == 200) {
                successAlert(res.data.msg);
                //重新请求user列表
                this.asyncManageList();
                //重新请求user总条数
                this.asyncManageCount()
              } else {
                warningAlert(res.data.msg);
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
      }
    },
    edit(uid) {
      this.$emit("edit", uid);
    },
    //当当前页码数发生变化
    changePage(e){
        this.asyncManagePage(e)
    }
  },
  computed: {
    ...mapGetters({
      manageList: "manage/list",
      manageCount: "manage/count",
      manageSize: "manage/size",
    }),
  },
  mounted() {
     this.asyncManageCount(),
    this.asyncManagePage(1);
  },
};
</script>

<style>
</style>